<?php
namespace hec\core;

use app\library\facade\Config;
/**
 * 签名
 * Class Signature
 * @package hec\core
 */
class Signature
{
    private $key;

    private $version_no;

    private $wx_shop;

    public function __construct()
    {
        $this->key = Config::get('hec.key');
        $this->wx_shop = Config::get('hec.wx_shop');
        $this->version_no = Config::get('hec.version_no');
    }

    /**
     * 生成签名
     *
     * @param array $data
     * @return string
     */
    public function generateSign(array $data = [])
    {
        return strtoupper(MD5(strtoupper(MD5($this->key . $this->version_no . json_encode($data))) . $this->wx_shop));
    }

    /**
     * 生成header头
     *
     * @param $data
     * @return string[]
     */
    public function generateHeader($data)
    {
        return [
            'Accept' => 'application/json',
            'Content-Type' => 'application/json;charset=utf-8',
            "sign" => $this->generateSign($data),
            "token" => $this->wx_shop
        ];
    }

}